#pragma once
#include <vector>
#include <WinSvc.h>
#define ErrorOut(dwError_) {LPVOID lpMsgBuf_;FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,NULL,\
   dwError_,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),(LPTSTR) &lpMsgBuf_,0,NULL); MessageBox(NULL,(LPCTSTR)lpMsgBuf_,TEXT("Error"),MB_ICONERROR);LocalFree(lpMsgBuf_);}
#ifndef _tstring
#	ifdef _UNICODE
#		define _tstring std::wstring
#	else
#		define _tstring std::string
#	endif
#endif

class CRegister
{
public:
	CRegister(void);
	~CRegister(void);

	enum {NONE ,REG_TYPE ,SVC_TYPE };
	static _tstring ReadValue(const TCHAR* szKeyPath ,DWORD& dwType );
	static bool WriteValue(const TCHAR* szKeyPath, BYTE* byValue,DWORD nLen ,DWORD dwType);
	static bool WriteValue(const TCHAR* szKeyPath, const TCHAR* szValue ,DWORD dwType);
	static DWORD QuerySerice(const TCHAR* szService);
	static BOOL ConfigService(const TCHAR* szService, DWORD dwStart);
private:
	static TCHAR* GetKey(const TCHAR* szKeyPath);
	static HKEY OpenKey(const TCHAR* szKeyPath);
	static DWORD QueryKey(const TCHAR* szKeyPath ,DWORD& dwType  ,BYTE*& byData);
	static TCHAR* GetSubKey(const TCHAR* szKeyPath, bool bSecond = false);
public:
	static const TCHAR* TypeToString(DWORD dwType,int nMode);
	static DWORD TypeToWord(const TCHAR* szType,int nMode);
#   define REG_TYPE_COUNT 14
	static const DWORD m_dwType[REG_TYPE_COUNT];
	static const TCHAR* m_szRegType[REG_TYPE_COUNT];
#   define SVC_TYPE_COUNT 5
	static const DWORD m_dwSvcType[SVC_TYPE_COUNT];
	static const TCHAR* m_szSvcType[SVC_TYPE_COUNT];
	static const void* Conversion(const TCHAR* szSource, void* szDest,DWORD RegType);
};

